package artid.com.arttogo.activity;

import android.app.Activity;
import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.webkit.JavascriptInterface;
import android.webkit.JsPromptResult;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.bumptech.glide.Glide;
import com.iflytek.cloud.InitListener;
import com.iflytek.cloud.SpeechConstant;
import com.iflytek.cloud.SpeechError;
import com.iflytek.cloud.SpeechSynthesizer;
import com.iflytek.cloud.SynthesizerListener;

import java.util.ArrayList;
import java.util.List;

import artid.com.arttogo.R;
import artid.com.arttogo.adapter.ArtListDetailAdapter;
import artid.com.arttogo.adapter.ArtNewsAdapter;
import artid.com.arttogo.bean.ArtComment;
import artid.com.arttogo.bean.ArtistFollow;
import artid.com.arttogo.bean.NewsContent;
import artid.com.arttogo.bean.NewsList;
import artid.com.arttogo.bean.OneStateIntParser;
import artid.com.arttogo.bean.ShowPhoto;
import artid.com.arttogo.db.Cache;
import artid.com.arttogo.network.AppUtil;
import artid.com.arttogo.network.VolleyBasic;
import artid.com.arttogo.network.VolleyCallback;
import artid.com.arttogo.network.VolleyData;
import artid.com.arttogo.network.VolleyMap;
import artid.com.arttogo.utils.Config;
import artid.com.arttogo.utils.ToastUtil;
import artid.com.arttogo.view.MyEditText;
import artid.com.arttogo.view.MyListView;
import artid.com.arttogo.view.ZoomScollView;
import artid.com.arttogo.view.pulllist.PullToRefreshLayout;

import static artid.com.arttogo.network.AppUtil.isCollect;

/**
 * 资讯详情
 */
public class ArtNewsDetailActivity extends BaseActivity implements
        OnClickListener {
    //资讯的列表和评论的列表
    MyListView mListRelaNews, mListComment;
    WebView mWebView;
    String id;
    ArtNewsAdapter adapterNews;
    ZoomScollView mScollView;
    private int page = 1, pagesize = 10;
    ArtListDetailAdapter adapter;
    //评论输入
    MyEditText mEditCmt;
    TextView mTextReplyNum, mTextLikeNum;
    private TextToSpeech mSpeech;
    ImageView mViewSpeech;
    View mViewCmt;
    ImageView mViewLike,mCollection;
    String strSpeakContent = "";
    WebSettings mWebSettings;
    List<ShowPhoto> showlist;
    ShowPhoto photoItem;
    View mViewMore;
    NewsContent itemMain;
    static Dialog progressDialog;
    Boolean isCommend = false;
    TextView mTextCommentTag;

    //点击查看大图
    class ImagesClick {

        @JavascriptInterface
        public void clickOnAndroid(String s) {
            // ToastUtil.toast(mContext, s);
            Intent intent = new Intent(mContext, PhotoActivity.class);
            intent.putExtra("item", photoItem);
            intent.putExtra(PhotoActivity.EXTRA_IMAGE_INDEX, Integer.valueOf(s));
            startActivity(intent);
        }

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        id = getIntent().getExtras().getString("id");
        setContentView(R.layout.activity_artnews_detail);
        mContext = ArtNewsDetailActivity.this;
        IntentFilter filter = new IntentFilter("com.ArtNewsDetailActivity.receiver");
        registerReceiver(broadcastReceiver, filter);
        mTextCommentTag = (TextView) findViewById(R.id.newsdet_pl_tag);
        mViewMore = (View) findViewById(R.id.CollectDetailFragment_HideTitle_shareBtn);
        mViewMore.setVisibility(View.VISIBLE);
        mViewMore.setOnClickListener(this);
        mScollView = (ZoomScollView) findViewById(R.id.newsdet_scroll);
        mViewCmt = (View) findViewById(R.id.newsdet_pl);
        mViewCmt.setOnClickListener(this);
        mViewLike = (ImageView) findViewById(R.id.newsdet_like);
        mViewLike.setOnClickListener(this);
        mCollection = (ImageView) findViewById(R.id.ArtNewsDetail_collection);
        mCollection.setOnClickListener(this);
        mWebView = (WebView) findViewById(R.id.newsdet_webview);
        mWebView.setWebChromeClient(new BasicWebChromeClient());
        mWebSettings = mWebView.getSettings();
        mWebSettings.setAppCacheEnabled(true);
        mWebSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
        mWebSettings.setJavaScriptEnabled(true);
        ImagesClick ImagesClick = new ImagesClick();
        mWebView.addJavascriptInterface(ImagesClick, "demo");

        mListComment = (MyListView) findViewById(R.id.newsdet_comment);
        mListRelaNews = (MyListView) findViewById(R.id.newsdet_relatenews);
        mTextReplyNum = (TextView) findViewById(R.id.newsdet_reply_num);
        mTextLikeNum = (TextView) findViewById(R.id.tv_like_sum);
        mEditCmt = (MyEditText) findViewById(R.id.newsdet_edit);
        mBack = (ImageView) findViewById(R.id.CollectDetailFragment_HideTitle_backBtn);
        mTittle = (TextView) findViewById(R.id.CollectDetailFragment_HideTitle_titleName);
        mTittle.setText("资讯详情");
        mViewSpeech = (ImageView) findViewById(R.id.newsdet_read);
        mViewSpeech.setOnClickListener(this);
        mBack.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                finish();
            }
        });
        mPullLayout = (PullToRefreshLayout) findViewById(R.id.refresh_view);
        mPullLayout.setVisibility(View.INVISIBLE);
        mPullLayout.setOnRefreshListener(new PullToRefreshLayout.OnRefreshListener() {

            @Override
            public void onRefresh(PullToRefreshLayout pullToRefreshLayout) {
                // TODO Auto-generated method stub
                page = 1;

                reqData();
                reqCmtData();
                // reqisLike(id);
            }

            @Override
            public void onLoadMore(PullToRefreshLayout pullToRefreshLayout) {
                // TODO Auto-generated method stub
                // pullToRefreshLayout.setBottomDismiss();
                page++;
                reqCmtData();
            }
        });

        mWebView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(WebView view, String url) {

                super.onPageFinished(view, url);
                mPullLayout.setVisibility(View.VISIBLE);
                disMissLoding();
                reqCmtData();

            }

        });
        mEditCmt.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            public boolean onEditorAction(TextView v, int actionId,
                                          KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_DONE
                        || actionId == EditorInfo.IME_ACTION_SEARCH
                        || (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
                    if (TextUtils.isEmpty(mEditCmt.getText().toString())) {
                        Config.showTip(mContext, "评论不能为空");
                        return false;
                    }
                    if (TextUtils.isEmpty(mEditCmt.getHint().toString())) {
                        isReplyPerson = false;
                    }
                    if (isReplyPerson) {
                        Replycomment(commentId);
                    } else {
                        reqArtReplycomment();
                    }

                    return false;
                }
                return false;
            }
        });
        showLoding(mContext);
        initSound();
        reqData();
        // reqCmtData();
    }

    SpeechSynthesizer mTts;

    void initSound() {
        //1.创建SpeechSynthesizer对象, 第二个参数：本地合成时传InitListener
        mTts = SpeechSynthesizer.createSynthesizer(ArtNewsDetailActivity.this, new InitListener() {

            @Override
            public void onInit(int arg0) {
                // TODO Auto-generated method stub

            }
        });
        //2.合成参数设置，详见《科大讯飞MSC API手册(Android)》SpeechSynthesizer 类
        //mTts.setParameter(SpeechConstant.VOICE_NAME, "xiaoyan");//设置发音人
        mTts.setParameter(SpeechConstant.SPEED, "50");//设置语速
        mTts.setParameter(SpeechConstant.VOLUME, "80");//设置音量，范围0~100
        mTts.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_CLOUD); //设置云端
        //设置合成音频保存位置（可自定义保存位置），保存在“./sdcard/iflytek.pcm”
        //保存在SD卡需要在AndroidManifest.xml添加写SD卡权限
        //如果不需要保存合成音频，注释该行代码
//		mTts.setParameter(SpeechConstant.TTS_AUDIO_PATH, "./sdcard/iflytek.pcm");  
        //3.开始合成

    }

    ArrayList<NewsList> newsLists;

    void reqData() {
        VolleyBasic.getInstanceNoDialog(ArtNewsDetailActivity.this).post(
                Cache.newsContent, VolleyMap.getInstance().newsContent(id),
                NewsContent.class, new VolleyCallback() {

                    @Override
                    public void onSuccess(VolleyData vd) {
                        // TODO Auto-generated method stub

                        String num = "0";
                        num = vd.getObj().optString("num");
                        if (num == null) {
                            num = "";
                        }

                        if (TextUtils.isEmpty(num) | num.equals("0")) {
                            mTextLikeNum.setVisibility(View.GONE);
                        } else {
                            mTextLikeNum.setVisibility(View.VISIBLE);
                            mTextLikeNum.setText(num);
                        }

                        final NewsContent itemContent = (NewsContent) vd
                                .getData();
                        itemMain = itemContent;
                        if (itemContent.getIs_commend() == 1) {
                            isCommend = true;
                            mViewLike
                                    .setImageResource(R.drawable.jg_xq_good_sel);
                        } else {
                            mViewLike
                                    .setImageResource(R.drawable.jg_xq_good_nor);
                            isCommend = false;
                        }
                        if (itemMain.getIs_collection() == 0) {
                            mCollection.setImageResource(R.drawable.ppxq_ico_sc);
                        } else {
                            mCollection.setImageResource(R.drawable.ppxq_ico_sc_sel);
                        }

                        showlist = new ArrayList<ShowPhoto>();
                        for (int i = 0; i < itemContent.getImgurl().size(); i++) {
                            ShowPhoto item = new ShowPhoto();
                            item.setUrl(itemContent.getImgurl().get(i));
                            showlist.add(item);
                        }
                        photoItem = new ShowPhoto();
                        photoItem.setList(showlist);

                        mWebView.loadUrl(itemContent.getWeburl());
                        newsLists = new ArrayList<NewsList>();
                        for (int i = 0; i < itemContent.getOtherinfoList()
                                .size(); i++) {
                            NewsContent.OtherInfo item = itemContent.getOtherinfoList()
                                    .get(i);
                            NewsList nlitem = new NewsList();
                            nlitem.setCatname(item.getCatname());
                            nlitem.setCreate_time(item.getCreate_time());
                            nlitem.setId(item.getId());
                            nlitem.setImgUrl(item.getImgUrl());
                            nlitem.setTop(item.getTop());
                            nlitem.setTitle(item.getTitle());
                            newsLists.add(nlitem);
                        }

                        adapterNews = new ArtNewsAdapter(mContext, newsLists);
                        mListRelaNews.setAdapter(adapterNews);
                        mListRelaNews
                                .setOnItemClickListener(new OnItemClickListener() {

                                    @Override
                                    public void onItemClick(
                                            AdapterView<?> arg0, View arg1,
                                            int arg2, long arg3) {
                                        // TODO Auto-generated method stub
                                        Intent intent = new Intent(mContext,
                                                ArtNewsDetailActivity.class);
                                        intent.putExtra("id",
                                                newsLists.get(arg2).getId());
                                        startActivity(intent);
                                    }
                                });
                        strSpeakContent = itemContent.getContent();

                    }

                    @Override
                    public void onError(VolleyError volleyError) {
                        // TODO Auto-generated method stub

                    }
                });
    }

    PullToRefreshLayout mPullLayout;
    PopupWindow mPw;
    TextView report, reply, cancel;
    String commentId = "";
    Boolean isReplyPerson = false;

    void reqCmtData() {
        VolleyBasic.getInstanceNoDialog(ArtNewsDetailActivity.this).post(
                Cache.zxcommentList,
                VolleyMap.getInstance().zxCommentList(String.valueOf(page),
                        String.valueOf(pagesize), id), ArtComment.class,
                new VolleyCallback() {

                    @Override
                    public void onSuccess(VolleyData vd) {
                        // TODO Auto-generated method stub

                        ArtComment itemContent = (ArtComment) vd.getData();
                        mPullLayout.loadmoreFinish(mPullLayout.SUCCEED);
                        final List<ArtComment> list = (List<ArtComment>) vd
                                .getList();
                        if (list.isEmpty()) {
                            if (page == 1) {
                                mTextCommentTag.setText("暂无评论");
                            }

                            // Config.showTip(CollectionDetailsActivity.this,
                            // "无数据");
                            return;
                        }
                        if (page != 1) {
                            adapter.addList(list);
                            mListComment
                                    .setOnItemClickListener(new OnItemClickListener() {

                                        @Override
                                        public void onItemClick(
                                                AdapterView<?> arg0, View arg1,
                                                int arg2, long arg3) {
                                            // TODO Auto-generated method stub
                                            String replyPreFix = "";
                                            replyPreFix = "回复"
                                                    + adapter.listdata
                                                    .get(arg2)
                                                    .getRealname()
                                                    + ":";
                                            commentId = adapter.listdata.get(
                                                    arg2).getMessid();
                                            isReplyPerson = true;
                                            startComment(replyPreFix);
                                        }
                                    });

                            return;
                        }
                        String num = "0";
                        num = vd.getObj().optString("num");
                        if (num == null | num.equals("0")) {
                            num = "";
                        }
                        if (num.equals("") | num.equals("0")) {
                            mTextReplyNum.setVisibility(View.GONE);
                        } else {
                            mTextReplyNum.setVisibility(View.VISIBLE);
                            mTextReplyNum.setText(num);
                        }

                        adapter = new ArtListDetailAdapter(mContext);
                        adapter.setdata(list);
                        mListComment.setAdapter(adapter);

                        LayoutInflater layoutInflater = (LayoutInflater) mContext
                                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                        View prView = layoutInflater.inflate(
                                R.layout.pop_comment, null);// 自定义的布局文件
                        report = (TextView) prView
                                .findViewById(R.id.cmt_report);
                        reply = (TextView) prView.findViewById(R.id.cmt_reply);
                        cancel = (TextView) prView
                                .findViewById(R.id.cmt_cancel);
                        mPw = new PopupWindow(prView,
                                LayoutParams.WRAP_CONTENT,
                                LayoutParams.WRAP_CONTENT);
                        mPw.setBackgroundDrawable(new BitmapDrawable());
                        mPw.setOutsideTouchable(true);
                        mListComment
                                .setOnItemClickListener(new OnItemClickListener() {

                                    @Override
                                    public void onItemClick(
                                            AdapterView<?> arg0, View arg1,
                                            final int arg2, long arg3) {
                                        // TODO Auto-generated method stub
                                        // String replyPreFix = "";
                                        // replyPreFix = "回复"
                                        // + adapter.listdata.get(arg2)
                                        // .getRealname() + ":";
                                        // isReplyPerson = true;
                                        // commentId =
                                        // adapter.listdata.get(arg2)
                                        // .getMessid();
                                        // startComment(replyPreFix);

                                        reply.setOnClickListener(new OnClickListener() {

                                            @Override
                                            public void onClick(View arg0) {
                                                // TODO Auto-generated method
                                                // stub
                                                mPw.dismiss();
                                                String replyPreFix = "";
                                                replyPreFix = "回复"
                                                        + adapter.listdata.get(
                                                        arg2)
                                                        .getRealname()
                                                        + ":";
                                                commentId = adapter.listdata
                                                        .get(arg2).getMessid();
                                                isReplyPerson = true;
                                                startComment(replyPreFix);
                                            }
                                        });
                                        cancel.setOnClickListener(new OnClickListener() {

                                            @Override
                                            public void onClick(View arg0) {
                                                // TODO Auto-generated method
                                                // stub
                                                mPw.dismiss();
                                            }
                                        });
                                        if (list.get(arg2).getIsme()
                                                .equals("1")) {
                                            report.setText("删除");
                                            report.setOnClickListener(new OnClickListener() {

                                                @Override
                                                public void onClick(View arg0) {
                                                    // TODO Auto-generated
                                                    // method stub
                                                    reqDeltCmt(list.get(arg2)
                                                            .getMessid());
                                                    adapter.listdata
                                                            .remove(arg2);
                                                    adapter.notifyDataSetChanged();
                                                    mPw.dismiss();

                                                }
                                            });
                                        } else {
                                            report.setOnClickListener(new OnClickListener() {

                                                @Override
                                                public void onClick(View arg0) {
                                                    // TODO Auto-generated
                                                    // method stub
                                                    mPw.dismiss();
                                                    Intent intent = new Intent(
                                                            mContext,
                                                            ReportActivity.class);
                                                    intent.putExtra("id", list
                                                            .get(arg2)
                                                            .getMessid());
                                                    intent.putExtra("type", "2");
                                                    startActivity(intent);
                                                }
                                            });
                                        }

                                        // Drawable dr =
                                        // this.getResources().getDrawable(R.drawable.list_bg_click);
                                        //
                                        // mPw.setBackgroundDrawable(dr);

                                        mPw.showAsDropDown(arg1);
                                    }
                                });

                    }

                    @Override
                    public void onError(VolleyError volleyError) {
                        // TODO Auto-generated method stub

                    }
                });
    }

    void reqDeltCmt(final String id) {

        VolleyBasic.getInstance((Activity) mContext).post(Cache.delcomment,
                VolleyMap.getInstance().delcomment(id), OneStateIntParser.class,
                new VolleyCallback() {

                    @Override
                    public void onSuccess(VolleyData vd) {
                        // TODO Auto-generated method stub
                        if (vd.getCode() == -99) {
                            AppUtil.Logout(mContext);
                            AppUtil.LoginVer(mContext);
                            return;
                        }

                    }

                    @Override
                    public void onError(VolleyError volleyError) {
                        // TODO Auto-generated method stub

                    }
                });
    }

    void reqArtReplycomment() {
        VolleyBasic.getInstance((Activity) mContext).post(
                Cache.docReplycomment,
                VolleyMap.getInstance().zxartReplycomment(
                        AppUtil.getUser().getToken(), id,
                        mEditCmt.getText().toString()), ArtistFollow.class,
                new VolleyCallback() {
                    @Override
                    public void onSuccess(VolleyData vd) {
                        // TODO Auto-generated method stub
                        if (vd.getCode() == -99) {
                            Config.showTip(mContext, "请先登录");
                            AppUtil.Logout(mContext);
                            AppUtil.LoginVer(mContext);
                            return;
                        }
                        ArtistFollow list = (ArtistFollow) vd.getData();

                        if (list.getState().equals("1")) {
                            page = 1;
                            reqCmtData();
                            mEditCmt.setText("");
                            // setColLikeComment(true, textpl);
                        }
                    }

                    @Override
                    public void onError(VolleyError volleyError) {
                        // TODO Auto-generated method stub

                    }
                });

    }

    // 回复某人
    void Replycomment(String commentid) {
        if (TextUtils.isEmpty(mEditCmt.getText().toString())) {
            Config.showTip(mContext, "回复不能为空");
            return;
        }
        String contentString = "";
        // if (editComment.getHint().toString()
        // .contains(AppUtil.getUser().getRealname())) {
        // reqArtReplycomment();
        // return;
        // } else {
        // contentString = editComment.getHint()
        // + editComment.getText().toString();
        // }

        VolleyBasic.getInstance((Activity) mContext).post(
                Cache.docAnswercomment,
                VolleyMap.getInstance().zxartAnswercomment(id,
                        mEditCmt.getText().toString(), commentid),
                ArtistFollow.class, new VolleyCallback() {
                    @Override
                    public void onSuccess(VolleyData vd) {
                        if (vd.getCode() == -99) {
                            Config.showTip(mContext, "请先登录");
                            AppUtil.Logout(mContext);
                            AppUtil.LoginVer(mContext);
                            return;
                        }
                        ArtistFollow list = (ArtistFollow) vd.getData();

                        if (list.getState().equals("1")) {
                            reqCmtData();
                            isReplyPerson = false;
                            mEditCmt.setText("");
                            // setColLikeComment(true, textpl);
                        }
                    }

                    @Override
                    public void onError(VolleyError volleyError) {
                        // TODO Auto-generated method stub
                        Log.d("log", "回复出错:" + volleyError.toString());
                    }
                });

    }

    void startComment(String strPreFix) {
        mEditCmt.setHint(strPreFix);
        mEditCmt.setFocusable(true);
        InputMethodManager imm = (InputMethodManager) mEditCmt.getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
        // mscroll.fullScroll(ScrollView.FOCUS_DOWN);
        // hideView.setVisibility(View.VISIBLE);
        mEditCmt.requestFocus();
    }

    void hideKeyBoard() {
        InputMethodManager imm = (InputMethodManager) mContext.getSystemService("input_method");
        if (imm != null) {
            imm.hideSoftInputFromWindow(getWindow().getDecorView()
                    .getWindowToken(), 0);
        }
        // hideView.setVisibility(View.GONE);
    }

    protected class BasicWebChromeClient extends WebChromeClient {

        @Override
        public boolean onJsAlert(WebView view, String url, String message,
                                 JsResult result) {
            return super.onJsAlert(view, url, message, result);
        }

        @Override
        public boolean onJsConfirm(WebView view, String url, String message,
                                   JsResult result) {
            return super.onJsConfirm(view, url, message, result);
        }

        @Override
        public boolean onJsPrompt(WebView view, String url, String message,
                                  String defaultValue, JsPromptResult result) {
            return super.onJsPrompt(view, url, message, defaultValue, result);
        }

        @Override
        public boolean onJsBeforeUnload(WebView view, String url,
                                        String message, JsResult result) {
            return super.onJsBeforeUnload(view, url, message, result);
        }

    }

    //点赞接口
    void reqZxLike(final Boolean setLike) {
        String tag = "";
        if (setLike) {
            tag = "1";
        } else {
            tag = "2";
        }
        VolleyBasic.getInstance((Activity) mContext).post(Cache.newCommend,
                VolleyMap.getInstance().newCommend(id, tag),
                ArtistFollow.class, new VolleyCallback() {

                    @Override
                    public void onSuccess(VolleyData vd) {
                        // TODO Auto-generated method stub
                        ArtistFollow state = (ArtistFollow) vd.getData();
                        if (state.getState().equals("1")) {
                            String num = mTextLikeNum.getText().toString();
                            int i = 0;
                            try {
                                i = Integer.valueOf(num);
                            } catch (Exception e) {
                                // TODO: handle exception
                            }
                            if (setLike) {
                                isCommend = true;
                                mViewLike
                                        .setImageResource(R.drawable.jg_xq_good_sel);
                                i++;
                                mTextLikeNum.setText(i + "");
                            } else {
                                isCommend = false;
                                mViewLike
                                        .setImageResource(R.drawable.jg_xq_good_nor);
                                i--;
                                mTextLikeNum.setText(i + "");
                            }
                        }
                        // List<ArtList> list = (List<ArtList>)vd.getList();
                        // if (list.isEmpty()) {
                        // Config.showTip(MoreCollectionsActivity.this, "无数据");
                        return;
                        // }
                        // ArtistInfo list = (ArtistInfo)vd.getData();
                    }

                    @Override
                    public void onError(VolleyError volleyError) {
                        // TODO Auto-generated method stub

                    }
                });
    }

    static ImageView fireImg;

    public static void showLoding(Context activity) {
        if (progressDialog == null) {
            LayoutInflater inflater = LayoutInflater.from(activity);
            View v = inflater.inflate(R.layout.loading, null);// 得到加载view
            RelativeLayout layout = (RelativeLayout) v
                    .findViewById(R.id.rel_dialog);// 加载布局
            fireImg = (ImageView) v.findViewById(R.id.iv);
            final AnimationDrawable animDrawable = (AnimationDrawable) fireImg
                    .getBackground();
            fireImg.post(new Runnable() {
                @Override
                public void run() {
                    animDrawable.start();
                }
            });
            progressDialog = new Dialog(activity, R.style.dialog);// 创建自定义样式dialog
            progressDialog.setCancelable(false);// 不可以用“返回键”取消
            progressDialog.setContentView(layout,
                    new LinearLayout.LayoutParams(
                            LinearLayout.LayoutParams.FILL_PARENT,
                            LinearLayout.LayoutParams.FILL_PARENT));// 设置布局
        }
        if (!progressDialog.isShowing()) {
            progressDialog.show();
        }
    }

    public static void disMissLoding() {
        if (progressDialog != null && progressDialog.isShowing()) {
            progressDialog.dismiss();
            progressDialog = null;
        }
    }

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        switch (arg0.getId()) {
            case R.id.newsdet_read:
                if (!mTts.isSpeaking()) {
                    Glide.with(mContext).load(R.raw.speak).asGif().dontAnimate().into(mViewSpeech);
                    mTts.startSpeaking(strSpeakContent, new SynthesizerListener() {

                        @Override
                        public void onSpeakResumed() {
                            // TODO Auto-generated method stub

                        }

                        @Override
                        public void onSpeakProgress(int arg0, int arg1, int arg2) {
                            // TODO Auto-generated method stub

                        }

                        @Override
                        public void onSpeakPaused() {
                            // TODO Auto-generated method stub

                        }

                        @Override
                        public void onSpeakBegin() {
                            // TODO Auto-generated method stub

                        }

                        @Override
                        public void onEvent(int arg0, int arg1, int arg2, Bundle arg3) {
                            // TODO Auto-generated method stub

                        }

                        @Override
                        public void onCompleted(SpeechError arg0) {
                            // TODO Auto-generated method stub

                        }

                        @Override
                        public void onBufferProgress(int arg0, int arg1, int arg2, String arg3) {
                            // TODO Auto-generated method stub

                        }
                    });
                } else {
                    Glide.with(mContext).load(R.drawable.zxxq_btn_read).dontAnimate().into(mViewSpeech);
                    mTts.stopSpeaking();
                }

//			speechText(arg0);
                break;
            case R.id.newsdet_pl:
                mScollView.fullScroll(ScrollView.FOCUS_DOWN);
                break;
            case R.id.newsdet_like:
                if (isCommend) {
                    reqZxLike(false);
                } else {
                    reqZxLike(true);
                }

                break;
            case R.id.CollectDetailFragment_HideTitle_shareBtn:
                //分享按钮
                Boolean isCollection = false;//是否已被收藏
                if (itemMain != null) {
                    if (itemMain.getIs_collection() == 0) {
                        isCollection = false;
                    } else {
                        isCollection = true;
                    }
                    AppUtil.shareNews(mContext, itemMain.getInfotitle(), itemMain.getContent(),
                            itemMain.getShareurl(), itemMain.getWeburl() + "&type=1", id, isCollection);
                }
                break;
            case R.id.ArtNewsDetail_collection:
                //收藏
                if (itemMain != null) {
                    if (itemMain.getIs_collection() == 0) {
                        isCollection = false;
                    } else {
                        isCollection = true;
                    }
                    collection(ArtNewsDetailActivity.this,id,isCollection,itemMain);
                }
            default:
                break;
        }
    }

    /**
     * 拍卖行收藏
     * 收藏ID	contentid
     * 收藏状态	setCollect	1：设置点赞   2：取消点赞
     */
    public  void collection(final Context mContext, final String id, final Boolean setCollect, final NewsContent bean) {
        String state = "";
        if (setCollect) {
            state = "2";
        } else {
            state = "1";
        }

        VolleyBasic.getInstance((Activity) mContext).post(Cache.documentCollection,
                VolleyMap.getInstance().documentCollection(id, state),
                OneStateIntParser.class, new VolleyCallback() {

                    @Override
                    public void onSuccess(VolleyData vd) {
                        // TODO Auto-generated method stub
                        OneStateIntParser mBean = (OneStateIntParser) vd.getData();
                        if (mBean.getState() == 1) {
                            if(setCollect){
                                bean.setIs_collection(0);
                                mCollection.setImageResource(R.drawable.ppxq_ico_sc);
                            }else{
                                bean.setIs_collection(1);
                                mCollection.setImageResource(R.drawable.ppxq_ico_sc_sel);
                            }

                        } else {
                            ToastUtil.toast(mContext, "收藏失败");
                        }
                    }

                    @Override
                    public void onError(VolleyError volleyError) {
                        // TODO Auto-generated method stub
                    }
                });
    }

    // 广播监听
    BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getBooleanExtra("Collect", false)) {
                //是否为收藏
                if (intent.getBooleanExtra("isCollect", true)) {
                    //设置为已收藏
                    itemMain.setIs_collection(1);
                } else {
                    //设置为未收藏
                    itemMain.setIs_collection(0);
                }
            }
        }
    };


    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
        mTts.stopSpeaking();
        // 退出时释放连接
        mTts.destroy();
    }

}
